package org.springblade.modules.restaurant.job;

import cn.hutool.core.date.DateUtil;
import com.aizuda.snailjob.client.job.core.annotation.JobExecutor;
import com.aizuda.snailjob.client.job.core.dto.JobArgs;
import com.aizuda.snailjob.client.model.ExecuteResult;
import com.aizuda.snailjob.common.log.SnailJobLog;
import lombok.AllArgsConstructor;
import org.springblade.modules.restaurant.service.IPerformanceRatingService;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 统计绩效评分
 *
 * @author harry
 * @公众号 Harry技术
 */
@Component
@AllArgsConstructor
@JobExecutor(name = "performanceRatingJobExecutor")
public class PerformanceRatingJobExecutor {
	private final IPerformanceRatingService performanceRatingService;

	public ExecuteResult jobExecute(JobArgs jobArgs) {
		SnailJobLog.REMOTE.info("统计绩效评分,jobArgs:{}", jobArgs);
		// 获取当月所有已审核任务记录 先统计用户绩效评分
		Date now = DateUtil.date();
		//  统计用户绩效评分
		performanceRatingService.genUserPerformanceRating(now);
		//  统计区域绩效评分
		performanceRatingService.genAreaPerformanceRating(now);

		return ExecuteResult.success();
	}

//	@PostConstruct
	public void init() {
		Date now = DateUtil.date();
		//  统计用户绩效评分
		performanceRatingService.genUserPerformanceRating(now);
		//  统计区域绩效评分
		performanceRatingService.genAreaPerformanceRating(now);
	}

}
